import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:sports_new/controller/service/resource_service.dart';
import 'package:sports_new/entity/my/expert/expert_apply_entity.dart';
import 'package:sports_new/resources/colours.dart';
import 'package:sports_new/resources/styles.dart';
import 'package:sports_new/utils/date_time_utils.dart';
import 'package:sports_new/utils/routes.dart';
import 'package:sports_new/utils/utils.dart';
import 'package:sports_new/view/my/expert/expert_contact_code.dart';
import 'package:sports_new/widgets/base/qkd_button.dart';

import '../../../widgets/base/qkd_text.dart';

class MyExpertApplyStatusPage extends StatefulWidget {
  const MyExpertApplyStatusPage({super.key});

  @override
  State<MyExpertApplyStatusPage> createState() =>
      _MyExpertApplyStatusPageState();
}

class _MyExpertApplyStatusPageState extends State<MyExpertApplyStatusPage> {
  ExpertApplyEntity data = Get.arguments is ExpertApplyEntity?Get.arguments:ExpertApplyEntity.fromJson(Get.arguments);
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // data = Get.arguments;
  }

  @override
  Widget build(BuildContext context) {
    String image = '';
    String title = '';
    // String content = '';
    if (data.status == 0 || data.status == 3) {
      image = 'expert_apply_status0.png';
      title = '审核中';
    } else if (data.status == 1) {
      image = 'expert_apply_status1.png';
      title = '审核通过';
    } else {
      image = 'expert_apply_status2.png';
      title = '审核未通过';
    }
    return Scaffold(
      backgroundColor: Colours.scaffoldBg,
      appBar: Styles.appBar(backgroundColor: Colours.transparent),
      body: SingleChildScrollView(
        child: Container(
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
          child: ClipRRect(
            borderRadius: const BorderRadius.all(Radius.circular(10)),
            child: Container(
              color: Colours.white,
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Container(
                    color: Colours.main,
                    height: 197,
                    width: double.infinity,
                    child: Column(
                      children: [
                        const SizedBox(height: 40),
                        Image.asset(
                          Utils.getImgPath(image),
                          width: 52,
                        ),
                        const SizedBox(height: 16),
                        QkdText(
                          title,
                          fontSize: 22,
                          color: Colours.white,
                          fontWeight: FontWeight.w500
                        ),
                        const SizedBox(height: 4),
                        if (data.status == 0 || data.status == 3)
                          QkdText(
                            '申请时间: ${DateTimeUtils.formatDateString(data.createTime!, 'yyyy-MM-dd HH:mm')}',
                            fontSize: 12, color: Colours.white
                          ),
                      ]
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.fromLTRB(30, 28, 30, 40),
                    child: bottom(),
                  )
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

  Widget bottom() {
    if (data.status == 0 || data.status == 3) {
      return Column(
        children: [
          textWidget('入驻专员会在5个工作日内联系您，并告知您申请最终的结果。'),
          const SizedBox(height: 28),
          const ExpertContactCode(),
          const SizedBox(height: 40),
          textWidget('您还可以通过上传其他证明图片，加速审核。'),
          const SizedBox(height: 20),
          uploadImageButton(),
        ],
      );
    } else if (data.status == 1) {
      return Column(
        children: [
          textWidget('经评估，您的综合素质符合平台专家入驻标准，已正式成为平台专家。'),
          const SizedBox(height: 28),
          const ExpertContactCode()
        ],
      );
    } else if (data.status == 2) {
      return Column(
        children: [
          if(data.reason.hasValue)
            textWidget("拒绝原因：${data.reason}")
          else
            textWidget('很遗憾，您的入驻申请未通过，如需再次申请，请联系客服后重新提交资料。'),
          const SizedBox(height: 16),
          applyButton(),
          Container(height: 40),
          const ExpertContactCode(),
        ],
      );
    } else {
      return Container();
    }
  }

  textWidget(String text) {
    return QkdText(text, fontSize: 16, textAlign: TextAlign.center);
  }

  Widget applyButton() {
    return QkdButton(
      onPressed: () {
        Get.offNamed(Routes.expertApply, arguments: data);
      },
      text: '重新申请',
      // side: BorderSide(color: Colours.blue2766D6),
      backgroundColor: Colours.main,
      foregroundColor: Colours.white,
      width: 140,
      height: 44,
      borderRadius: 8,
    );
  }

  uploadImageButton() {
    return QkdButton(
      onPressed: () {
        Get.offNamed(Routes.expertApply, arguments: data);
      },
      text: '上传图片',
      // side: BorderSide(color: Colours.blue2766D6),
      borderSide: const BorderSide(color: Colours.main,width: 0.5),
      // foregroundColor: Colours.white,
      width: 140,
      height: 44,
      borderRadius: 8,
    );
  }
}
// class ExpertApplySuccessPage extends StatelessWidget {
//   const ExpertApplySuccessPage({super.key});

//   @override
//   Widget build(BuildContext context) {

//   }
// }
